package com.wc.codeforces.思维.MEX_Destruction;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/12/21 9:06
 * @description https://codeforces.com/contest/2049/problem/A
 */
public class Main {
    /**
     * 思路：
     * 0次的, 全是 0
     * 1次的, 中间没有 0
     * 2次的, 全刷两遍就OK
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    static int[] a = new int[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            // 找到左右边第一个不是 0 的地方
            int l = 1, r = n;
            while (l <= n && a[l] == 0) l++;
            while (r >= 1 && a[r] == 0) r--;

            // l > r 说明全是0
            if (l > r) out.println(0);
            else {
                // 检查中间是否有 0
                boolean exist0 = false;
                for (int i = l; i <= r; i++) {
                    if (a[i] == 0) {
                        exist0 = true;
                        break;
                    }
                }
                if (exist0) out.println(2);
                else out.println(1);
            }
        }
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

